export default class orc_event{
    public static  _dir:any = {};

    public static add_listener(event_name:string, handler:any) 
    {   
        // 订阅事件
        if (this._dir[event_name]) {
            console.error('event register');
            delete this._dir[event_name];
        }
        // else {           
        //     this._dir[event_name] = [handler];
        // }
        this._dir[event_name] = [handler];
        console.log("add_listener:",this._dir);
    }

    public static dispatch_event(event_name:string,udata?:any) 
    {   
        //事件执行        
        console.log("params:",event_name,udata)
        if (!this._dir[event_name]) {
            return;
        }        
        if(udata == undefined)
        {
            this._dir[event_name][0]();  
        }   
        else
        {
            this._dir[event_name][0](udata);  
        }
    }

    public static clear_event(){
        this._dir = {};
    }
}
